package com.myebills.ebpsfrontend.cust.maxis;

import java.sql.*;
import java.util.*;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import com.myebills.ebpsfrontend.cust.controller.*;
import javax.servlet.http.HttpSession;
import com.ibm.logging.ILogger;
import com.ibm.logging.IRecordType;

public class CusBillDeliveryStatusServlet_v1r00 extends EbppxTransactionServlet {

    public void doTransaction(HttpServletRequest req, HttpServletResponse res) throws ServletException {
        ILogger trcLogger = null;
        trcLogger = getTraceLogger(req);
        final String fName = "doTransaction";
        if (trcLogger.isLogging())
            trcLogger.entry(IRecordType.TYPE_INFO, this, fName);

        final EbppxUrlManager urlManager = getUrlManager(req);

        final String accountNumber = urlManager.getSecureParameter("accNo");

        String pageNo = urlManager.getSecureParameter("pageNo");
        	if (pageNo.length() == 0) {
                pageNo = "1";
            }

        Vector vecData = new Vector();

        final HttpSession session = req.getSession(false);
        if (null == session)
                throw new IllegalStateException("no session established");

        //Get attribute from session for the logon user
        final EbppxEcsUser ecsUser = (EbppxEcsUser) session.getAttribute(EbppxConstants.ECS_USER);
        final Vector cfiAcctExtKeys = ecsUser.getAccountExternalKeys();
        final Vector cfiOldAccounts = ecsUser.getOldAccounts();

		//to get old acc no for selected new acc no
		String oldAccountNo = ecsUser.getOldAccount(cfiAcctExtKeys, cfiOldAccounts, accountNumber);


        try {

			//to check is there any old account number - start
			int oldAccountDisplayCount = 0;
			String oldAccountDisplay = "N";
			for (java.util.Enumeration enumAccounts = cfiAcctExtKeys.elements(); enumAccounts.hasMoreElements();) {
				final String tAccountNo = (String) enumAccounts.nextElement();

				if (!AcctDetails.getAcctKey(tAccountNo).equals("")) {
					oldAccountDisplayCount++;
				}

			}
			if (oldAccountDisplayCount > 0) {
				oldAccountDisplay = "Y";
			}
			req.setAttribute("oldAccountDisplay",oldAccountDisplay);
			//to check is there any old account number - end


            if(accountNumber!=null){
                System.out.println("accountnumber given..");
                vecData = EbppxCusDBUtil.processCUSSubscriptionReportData(accountNumber, oldAccountNo);
	    } //if accountNumber!=null

                req.setAttribute("acctExtKeys",cfiAcctExtKeys);
            	req.setAttribute("oldAccounts",cfiOldAccounts);
                req.setAttribute("BillDeliveryReportList", vecData);
                req.setAttribute("accNo", accountNumber);
                req.setAttribute("pageNo", pageNo);

                forwardToMappedUrl(req, res, EbppxConstants.URL_JSP_PARAM);

            }catch (SQLException e) {
                throw new ServletException(e);
            }catch (Throwable t){
                throw new ServletException(t.toString(), t);
            }finally {
	     } //finally




  }//doTransaction

}
